package com.hospitalsystem.service.impl;

import com.hospitalsystem.dao.MedicalRecordDao;
import com.hospitalsystem.entity.MedicalRecord;
import com.hospitalsystem.service.MedicalRecordService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (MedicalRecord)表服务实现类
 *
 * @author makejava
 * @since 2024-12-28 19:32:48
 */
@Service("medicalRecordService")
public class MedicalRecordServiceImpl implements MedicalRecordService {
    @Resource
    private MedicalRecordDao medicalRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param  mId
     * @return 实例对象
     */
    @Override
    public MedicalRecord queryById(String mId) {
        return this.medicalRecordDao.queryById(mId);
    }

    /**
     * 分页查询
     *
     * @param medicalRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<MedicalRecord> queryByPage(MedicalRecord medicalRecord, PageRequest pageRequest) {
        long total = this.medicalRecordDao.count(medicalRecord);
        return new PageImpl<>(this.medicalRecordDao.queryAllByLimit(medicalRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param medicalRecord 实例对象
     * @return 实例对象
     */
    @Override
    public MedicalRecord insert(MedicalRecord medicalRecord) {
        this.medicalRecordDao.insert(medicalRecord);
        return medicalRecord;
    }

    /**
     * 修改数据
     *
     * @param medicalRecord 实例对象
     * @return 实例对象
     */
    @Override
    public MedicalRecord update(MedicalRecord medicalRecord) {
        this.medicalRecordDao.update(medicalRecord);
        return this.queryById(medicalRecord.getMId());
    }

    /**
     * 通过主键删除数据
     *
     * @param  mId
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String mId) {
        return this.medicalRecordDao.deleteById(mId) > 0;
    }
}
